package com.coderjacky.search.server.controller;


import com.coderjacky.common.core.domain.Result;
import com.coderjacky.search.server.service.ProductService;
import com.coderjacky.search.server.vo.SearchParam;
import com.coderjacky.search.server.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/")
public class EsSearchController
{


    @Autowired
    private ProductService productService;

    @GetMapping("/")
    public Result<SearchResult> searchProduct(SearchParam searchParam){


        try {
            SearchResult result = productService.search(searchParam);
            return Result.success(result);
        } catch (IOException e) {
            return Result.error(e.getMessage());
        }
    }
}
